package com.woniu.humanresource.service.impl;

import com.woniu.humanresource.dao.UserDao;
import com.woniu.humanresource.entity.Position;
import com.woniu.humanresource.entity.User;
import com.woniu.humanresource.entity.User02;
import com.woniu.humanresource.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public List<User> selectAllUser(int pageIndex, int pageSize) {
        List<User> users = userDao.selectAllUser(pageIndex,pageSize);
        return users;
    }

    @Override
    public List<User> selectUserByCondition(int dapartid ) {
        List<User> users = userDao.selectUserByCondition(dapartid);
       //List<User> users = userDao.selectUserByCondition(dapartid,positionid);
        return users;
    }

    @Override
    public List<User> selectUserByCondition2(int dapartid, int positionid) {
        List<User> users = userDao.selectUserByCondition2(dapartid,positionid);
        return users;
    }

    @Override
    public List<User> selectUserByCondition3(int dapartid, int positionid, String username,int pageIndex, int pageSize) {
        List<User> users = userDao.selectUserByCondition3(dapartid,positionid,username,pageIndex,pageSize);
        return users;
    }

    @Override
    public List<Position> selectAllPosition() {
        List<Position> positions = userDao.selectAllPosition();
        return positions;
    }

    @Override
    public List<Position> selectPositionByCondition(int pnum) {
        List<Position> positions = userDao.selectPositionByCondition(pnum);
        return positions;
    }

    @Override
    public List<Position> selectPositionByCondition2(String pnum) {
        List<Position> positions = userDao.selectPositionByCondition2(pnum);
        return positions;
    }

    @Override
    public void updateUser(int id , int setpositionid) {
        userDao.updateUser(id, setpositionid);
    }

    @Override
    public void deleteUser(int id) {
        userDao.deleteUser(id);
    }

    @Override
    public int selectAllUserCount(int dapartid,int positionid) {
        int userCount = userDao.selectAllUserCount(dapartid,positionid);
        return userCount;
    }

    @Override
    public void resetpassword(int id, String password) {
        userDao.resetpassword(id, password);
    }

    public void insertUser(User02 u){
        u.setUname(u.getEid()+"abc");
        userDao.insertUser(u);
        userDao.updateuserStatus(u.getEid());
    }
}
